package gdconf

import (
	"server_cluster/common/logger"
)

// 武器配置表

type WeaponConfig struct {
	WeaponId         int32 `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 武器id
	WeaponType       int32 `csv:"WeaponType,omitempty"`                      // 武器类型
	WeaponStrikeType int32 `csv:"WeaponStrikeType,omitempty"`                // 武器打击类型
	AllowCompose     bool  `csv:"Build,omitempty"`                           // 是否允许合成
	LevelGroup       int32 `csv:"WeaponLevelGroup,omitempty"`                // 等级组
	PromoteGroup     int32 `csv:"WeaponPromoteGroup,omitempty"`              // 等阶组
	StarGroup        int32 `csv:"WeaponStarGroup,omitempty"`                 // 星级组
	BaseConvExp      int32 `csv:"WeaponExp,omitempty"`                       // 基础转化经验
}

func (w *WeaponConfig) TableName() string {
	return "config_weapon"
}

func (g *GameDataConfig) saveWeaponConfig() {
	saveTableToDb[WeaponConfig](g.Db, readTable[WeaponConfig](g.CsvPathPrefix+"Weapon.csv"))
}

func (g *GameDataConfig) loadWeaponConfig() {
	g.GameDataMaps.WeaponConfigMap = make(map[int32]*WeaponConfig)
	for _, weaponConfig := range loadTableFromDb[WeaponConfig](g.Db) {
		g.GameDataMaps.WeaponConfigMap[weaponConfig.WeaponId] = weaponConfig
	}
	logger.Info("WeaponConfig Count: %v", len(g.GameDataMaps.WeaponConfigMap))
}

func GetWeaponConfig(weaponId int32) *WeaponConfig {
	value, exist := CONF.GameDataMaps.WeaponConfigMap[weaponId]
	if !exist {
		logger.Error("[ConfigNotFound] WeaponConfig, weaponId: %v", weaponId)
		return nil
	}
	return value
}

func GetWeaponConfigMap() map[int32]*WeaponConfig {
	return CONF.GameDataMaps.WeaponConfigMap
}
